package br.indt.framework.ui.common;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import br.indt.framework.ui.ImageLoader;

/**
 * Display a image on screen
 * 
 * @author Nokia Institute of Technology
 *
 */
public abstract class ImageItem extends Widget
{
	protected int imageHeight = 115;

	protected int imageWidth =  240;
	protected int imageWidthLandscape =  320;
	
	public static int TYPE_FEED_IMAGE = 1;
	public static int TYPE_FEED_MAP = 2;
	
	protected Image placeHolder = null;
	public boolean map = false;
	
		
	public ImageItem(String name, Image image)
	{
		super(name);
		
		try 
		{
			this.placeHolder = ImageLoader.load("/icon/icon_location.png");
			if (image != null) 
			{
				backgroundImage = image;
			}
		}
		catch (Exception e) 
		{
			System.out.println("[ERROR] ImageItem::Constructor " + e);
		}
		
		calculateHeight();
	}
	
	public int getImageHeight() 
	{
		return imageHeight;
	}


	public void setImageHeight(int imageHeight) 
	{
		this.imageHeight = imageHeight;
	}

	public int getImageWidth() 
	{
		return imageWidth;
	}

	public void setImageWidth(int imageWidth) 
	{
		this.imageWidth = imageWidth;
	}

	public int getImageWidthLandscape() 
	{
		return imageWidthLandscape;
	}

	public void setImageWidthLandscape(int imageWidthLandscape) 
	{
		this.imageWidthLandscape = imageWidthLandscape;
	}
	
	public void setWidth(int width) 
	{
		this.width = width;
		
		try 
		{
			calculateHeight();
		}
		catch (Exception e)
		{
			System.out.println("[ERROR] ImageItem::::setWidth: " + e);
		}
	}

	protected void calculateHeight() {
		height =  topMargin + bottomMargin + imageHeight;

			height =+ 300;
	}

	public void paint(Graphics g, int x, int y, int maxWidth, int maxHeight) 
	{
		try 
		{
			x += leftMargin;
			
			y = 0;

			if (backgroundImage != null)
			{
					
					int menuBar = 0;
					g.drawImage(backgroundImage, x + (Display.getInstance().getWidth() / 2),  y + ((Display.getInstance().getHeight() - menuBar) / 2), Graphics.HCENTER | Graphics.VCENTER);
				
			}
			else
			{
				g.setColor(0xDDDDDD);
					g.fillRoundRect(x, y, Display.getInstance().getWidth(), Display.getInstance().getHeight(), 0, 0);
					g.drawImage(placeHolder, x + (Display.getInstance().getWidth()/ 2), y + (Display.getInstance().getHeight() / 2), Graphics.HCENTER | Graphics.VCENTER);
			}
		} catch (Exception e) {
			System.out.println("ImageItem::paint - " + e.getMessage());
		}
	}

	public void pressFire(){}
	
	public void setPlaceHolder(Image placeHolder) {
		this.placeHolder = placeHolder;
	}
	
	public boolean isMap() {
		return map;
	}

	public void setMap(boolean map) {
		this.map = map;
	}

}